package com.example.springflowable.controller;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.example.springflowable.common.Results;
import com.example.springflowable.service.NodeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.flowable.bpmn.model.FlowElement;
import org.flowable.bpmn.model.FlowNode;
import org.flowable.engine.ManagementService;
import org.flowable.engine.RepositoryService;
import org.flowable.engine.RuntimeService;
import org.flowable.engine.impl.cfg.ProcessEngineConfigurationImpl;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Classname NodeController
 * @Description TODO
 * @Date 2022/5/9 19:08
 * @Created by XiongXiong
 * @Author: X.I.O
 */
@RestController
@Api(tags = {"节点服务"})
@RequestMapping("node")
public class NodeController {

    Logger logger= LoggerFactory.getLogger(NodeController.class);

    @Autowired
    private NodeService nodeService;

    @ApiOperation("获取所有节点服务")
    @PostMapping("getallnode")
    public JSONObject getAllNodes(@RequestParam("processId")String processId){
        Map<String,Object> map = new HashMap<>();
        List<FlowElement> list=nodeService.getAllNodesByProcessId(processId,map);
        JSONArray jsonArray = new JSONArray();
        JSONObject obj = null;
        for (FlowElement ele : list) {
            obj=new JSONObject();
            obj.put("id",ele.getId());
            obj.put("name",ele.getName());
            jsonArray.add(obj);
        }
        return Results.success(jsonArray);
    }





}
